
/** 
 * @file		SPI.h
 * @brief				
 * @details	Project	: BHS-Ethernet 
 * 
 * 
 * @author	Seven Zeng
 * @date		30/11/2019
 * @copyright	MICC Tech All rights reserved
 * 
 ************************************************************** 
 * @par
 * 
 * 
 ************************************************************** 
 */
 
 
#ifndef __SPI_H__
#define __SPI_H__


//===============================INCLUDE==========================

#include "porting.h"
#include "HAL.h"
//================================================================


#ifdef __cplusplus
extern "C" {
#endif // #ifdef __cplusplus  



//=========================TYPE DEFINITIONS=======================

typedef struct {
	SPI_TypeDef *pInstance;		///< Pointer to SPI instance
	DMA_TypeDef *pDMAInstance;	///< Pointer to DMA instance connected to this SPI instance
	u32 baud;					///< Baud rate
	u32 format;					///< Format, TBD
	u32 rxDMAChannel;			///< rx DMA channel
	u32 txDMAChannel;			///< tx DMA channel

} T_SPI_INFO;

//================================================================




//=========================CONST DEFINITIONS======================


//================================================================




//=========================VARIABLE DECLARATIONS==================

//#ifdef SPI_DEF
//#define _SPI_DEF
//#else
//#define _SPI_DEF extern
//#endif
//_SPI_DEF 
//_SPI_DEF 



//================================================================




//=========================ROUTINE PROTOTYPES=====================

void SPI_Select(void);

void SPI_Deselect(void);


/**
 * --------------------------------------------------------------------------------
 * @fn void SPI_Init(T_SPI_INFO* pInfo, SPI_TypeDef *SPIx, u32 baud, u32 format);
 * @brief See implementation file for more detail
 * @param baud 
 * @param format 
 * @param pInfo 
 * @param SPIx 
 * @return None
 * @par Example
 * @see 
 */
void SPI_Init(T_SPI_INFO* pInfo, SPI_TypeDef *SPIx, u32 baud, u32 format);


/**
 * --------------------------------------------------------------------------------
 * @fn u8 SPI_ReadByte(T_SPI_INFO* pInfo);
 * @brief See implementation file for more detail
 * @param pInfo 
 * @return None
 * @par Example
 * @see 
 */
u8 SPI_ReadByte(T_SPI_INFO* pInfo);
u8 SPI_ReadByte_WithoutSelect(T_SPI_INFO* pInfo);

/**
 * --------------------------------------------------------------------------------
 * @fn u8 SPI_ReadWriteByte(T_SPI_INFO* pInfo, u8 value);
 * @brief See implementation file for more detail
 * @param pInfo 
 * @param value 
 * @return None
 * @par Example
 * @see 
 */
u8 SPI_ReadWriteByte(T_SPI_INFO* pInfo, u8 value);
u8 SPI_ReadWriteByte_WithoutSelect(T_SPI_INFO* pInfo, u8 value);

/**
 * --------------------------------------------------------------------------------
 * @fn void SPI_ReadWriteBlock(T_SPI_INFO* pInfo, u8* pSrc, u8* pDest, u16 count);
 * @brief See implementation file for more detail
 * @param count 
 * @param pDest 
 * @param pInfo 
 * @param pSrc 
 * @return None
 * @par Example
 * @see 
 */
void SPI_ReadWriteBlock(T_SPI_INFO* pInfo, u8* pSrc, u8* pDest, u16 count);
void SPI_ReadWriteBlock_WithoutSelect(T_SPI_INFO* pInfo, u8* pSrc, u8* pDest, u16 count);





//================================================================




#ifdef __cplusplus
}
#endif // #ifdef __cplusplus  



#endif // __SPI_H__ 
 


